package com.eh.rmi.remote.impl;

import com.eh.rmi.remote.MyRemote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;

/**
 * Created by David on 2016/5/2.
 */
public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {
    private static Logger logger = LoggerFactory.getLogger(MyRemoteImpl.class);

    protected MyRemoteImpl() throws RemoteException {
    }

    @Override
    public String sayHello() throws RemoteException {
        return "Server say, 'Hello, World!'";
    }

    public static void main(String[] args) {
        try {
            logger.info("注册Server");
            MyRemote myRemote = new MyRemoteImpl();
            LocateRegistry.createRegistry(6600);
            Naming.rebind("rmi://127.0.0.1:6600/RemoteHello", myRemote);
            logger.info("Server start");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
